<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增图书')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-book-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">ISBN：</label>
                <div class="col-sm-8">
                    <input name="isbn" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">书名：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">作者：</label>
                <div class="col-sm-8">
                    <input name="author" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">出版社：</label>
                <div class="col-sm-8">
                    <input name="publisher" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">出版日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="publishDate" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">原价：</label>
                <div class="col-sm-8">
                    <input name="oldPrice" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">现价：</label>
                <div class="col-sm-8">
                    <input name="newPrice" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">出版地：</label>
                <div class="col-sm-8">
                    <input name="authorLoc" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否套装：</label>
                <div class="col-sm-8">
                    <select name="suit" class="form-control m-b" th:with="type=${@dict.getType('sys_book_suit')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">图书类别：</label>
                <div class="col-sm-8">
                    <select name="category" class="form-control m-b" th:with="type=${@dict.getType('sys_book_category')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">图书描述：</label>
                <div class="col-sm-8">
                    <textarea name="info" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">图书图片URL：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="imgUrl">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="imgUrl" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">分类名称：</label>
                <div class="col-sm-8">
                    <select name="fenleiId" class="form-control m-b" id="fenlei">
<!--                        <option th:each="fenlei : ${fenleis}" th:text="${fenlei.name}" th:value="${fenlei.id}"></option>-->
                    </select>
<!--                    <select name="category" class="form-control m-b" th:with="type=${@dict.getType('sys_book_category')}">-->
<!--                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>-->
<!--                    </select>-->
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">

        var prefix = ctx + "business/book"
        $("#form-book-add").validate({
            focusCleanup: true
        });



        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-book-add').serialize());
            }
        }

        $("input[name='publishDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(".file-upload").fileinput({
            uploadUrl: ctx + 'common/upload',
            maxFileCount: 1,
            autoReplace: true
        }).on('fileuploaded', function (event, data, previewId, index) {
            $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        })
        $(function () {
            $.ajax({
                url: ctx+"business/fenlei/list",
                method:"get",
                success:function (data) {
                    var html = "";
                    for(var i=0;i<data.length;i++){ //遍历data数组
                        var fenlei = data[i];
                        // html +="<li><a href='"+contextPath+"/book/bookListByFenlei?fenlei="+fenlei.id+"' class='infNews_wrod_a'>"+fenlei.name+"</a></li>";
                        html +="<option value='"+fenlei.id+"'>"+fenlei.name+"</option>"
                    }

                    $("#fenlei").html(html);

                }
            })
        })
    </script>
</body>
</html>